﻿using UnityEngine;
using System.Collections;
using Game.Ani;

namespace Game
{
    /// <summary>
    /// 演员类，可播放动画、行走等
    /// </summary>
	public class ActorObj:InteractiveGameObj //继承于可互动类
	{
        /// <summary>
        /// 动画控制器
        /// <para>若有则与此类在同级物体中</para>
        /// </summary>
        protected AniController m_aniController;

        protected override void Start()
        {
            base.Start();

            m_aniController = GetComponent<AniController>();
        }

		//---------------------------------------------------------------------------
		//				Public area
		//---------------------------------------------------------------------------
		#region public area

        //--xz将恒定为0
        Vector3 _eulerBlockXZ = new Vector3(0, 0, 0);
        /// <summary>
        /// 将当前Transform水平转向某个Transform，不进行竖直操作
        /// </summary>
        /// <param name="target">指定某个目标，则可不定为玩家</param>
        /// <param name="lockVerticalRotation">是否锁定竖直方向的旋转，是则不会上下看player</param>
        public void LookAt(Transform target, bool lockVerticalRotation = true)
        {
            LookAt(target.position, lockVerticalRotation);
        }

        /// <summary>
        /// 将当前Transform水平转向某个Position，不进行竖直操作
        /// </summary>
        /// <param name="target">指定某个目标，则可不定为玩家</param>
        /// <param name="lockVerticalRotation">是否锁定竖直方向的旋转，是则不会上下看player</param>
        public void LookAt(Vector3 target, bool lockVerticalRotation = true)
        {
            //先看:如果目标不是活的玩家，那么看向某个指定目标
            m_transform.LookAt(target);

            if (lockVerticalRotation)
            {
                //因为旋转只针对左右旋转，即只取Y轴的变量，所以做一下操作，令Transform只在Y轴上旋转：
                _eulerBlockXZ.y = m_transform.eulerAngles.y;
                m_transform.eulerAngles = _eulerBlockXZ;
            }
        }
		#endregion

        #region Protected Area
        /// <summary>
        /// 往前行进一帧的距离
        /// </summary>
        protected void MoveForward(float speed)
        {
            m_transform.Translate(0, 0, speed * Time.deltaTime, Space.Self);        //Go for it!
        }

        #endregion

        //---------------------------------------------------------------------------
		//				Private area
		//---------------------------------------------------------------------------
		#region Private area
		#endregion
	}
}